/**
* Created with JetBrains WebStorm.
* User: scb
* Date: 11/4/13
* Time: 2:28 PM
* To change this template use File | Settings | File Templates.
*/

describe("locateMapController",function(){
    var locateMapController = null;
    beforeEach(function(){
        //need feature
        var t_alertCtrl = App.AlertController.create();
        var t_loadingCtrl = App.LoadingController.create();
        App.LocateMapController.reopen({

            init:function(){
                this.set('controllers.alert', t_alertCtrl);
                this.set('controllers.loading', t_loadingCtrl);
            }
        });
        locateMapController = App.LocateMapController.create();
    })

    it("prepareController; if branch - publicLocate.atmBranch", function(){
        App.RouteHistory.lastRoute = "publicLocate.atmBranch";
        var object = {
            position:{la:"", lo:""},
            channel:{opHours:[{fake:"data"},{fake:"data1"},{fake:"data2"}]}
        }
        App.Router.setParameter(object);
        var channelType = "all";
        spyOn(locateMapController, "set");
        locateMapController.prepareController(channelType);
        expect(locateMapController.set).toHaveBeenCalledWith("positionData",object.position);
        expect(locateMapController.set).toHaveBeenCalledWith("channel",object.channel);
        expect(locateMapController.set).toHaveBeenCalledWith("positionData",null);
        expect(locateMapController.set).toHaveBeenCalledWith("currentLocationMarker",null);
        expect(locateMapController.set).toHaveBeenCalledWith("showOpHours",true);
    })

    it("prepareController; else branch - publicLocate.atmBranch", function(){
        App.RouteHistory.lastRoute = "publicLocate.atmBranch";
        spyOn(locateMapController, "set");
        var object = {
            position:null,
            channel:{opHours:[{fake:"data"},{fake:"data1"},{fake:"data2"}]}
        }
        var channelType = "all";
        App.Router.setParameter(object);
        locateMapController.prepareController(channelType);
        expect(locateMapController.set).toHaveBeenCalledWith("channel",object.channel);
        expect(locateMapController.set).toHaveBeenCalledWith("showOpHours",true);
    });

    it("prepareController; if branch - securityLocate.atmBranch", function(){
        App.RouteHistory.lastRoute = "securityLocate.atmBranch";
        var object = {
            position:{la:"", lo:""},
            channel:{opHours:[{fake:"data"},{fake:"data1"},{fake:"data2"}]}
        }
        App.Router.setParameter(object);
        var channelType = "all";
        spyOn(locateMapController, "set");
        locateMapController.prepareController(channelType);
        expect(locateMapController.set).toHaveBeenCalledWith("positionData",object.position);
        expect(locateMapController.set).toHaveBeenCalledWith("channel",object.channel);
        expect(locateMapController.set).toHaveBeenCalledWith("positionData",null);
        expect(locateMapController.set).toHaveBeenCalledWith("currentLocationMarker",null);
        expect(locateMapController.set).toHaveBeenCalledWith("showOpHours",true);
    })

    it("prepareController; else branch - securityLocate.atmBranch", function(){
        App.RouteHistory.lastRoute = "securityLocate.atmBranch";
        spyOn(locateMapController, "set");
        var object = {
            position:null,
            channel:{opHours:[{fake:"data"},{fake:"data1"},{fake:"data2"}]}
        }
        var channelType = "all";
        App.Router.setParameter(object);
        locateMapController.prepareController(channelType);
        expect(locateMapController.set).toHaveBeenCalledWith("channel",object.channel);
        expect(locateMapController.set).toHaveBeenCalledWith("showOpHours",true);
    });

    it("prepareController; else branch - securityLocate.atmBranch", function(){
        App.RouteHistory.lastRoute = "securityLocate.atmBranch";
        spyOn(locateMapController, "set");
        var object = {
            position:null,
            channel:{opHours:[{}]}
        }
        var channelType = "all";
        App.Router.setParameter(object);
        locateMapController.prepareController(channelType);
        expect(locateMapController.set).toHaveBeenCalledWith("showOpHours",false);
    })

    describe("infoButtonAction", function(){
        beforeEach(function(){
            spyOn(locateMapController,"set");
        })

        it("infoButtonAction; if branch", function() {
            locateMapController.set("showInfoFlag", false);
            locateMapController.infoButtonAction();
            expect(locateMapController.set).toHaveBeenCalledWith("showInfoFlag",true);
        });
        it("infoButtonAction; else branch", function() {
            locateMapController.showInfoFlag = true; //("showInfoFlag", true);
            locateMapController.infoButtonAction();
            expect(locateMapController.set).toHaveBeenCalledWith("showInfoFlag",false);
        });
    })
})